package com.yf1706.service;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.yf1706.bean.CheckWithcard;
import com.yf1706.dao.jpa.ICheckAccountJDAO;
import com.yf1706.dao.jpa.ICheckWithCardJDAO;
import com.yf1706.dao.jpa.IEmpJDAO;
import com.yf1706.dao.mybatis.ICheckWithCardMDAO;
import com.yf1706.vo.CheckUPWithCardVO;
import com.yf1706.vo.CheckWithCardVO;

@Service
@Transactional(rollbackFor=Exception.class)
public class CheckWithCardService {
	@Autowired
   private 	ICheckWithCardJDAO cwcJdao;
	@Autowired
	private ICheckWithCardMDAO cwcMdao;
	@Autowired
	private  IEmpJDAO emJdao;
	@Autowired
	private ICheckAccountJDAO caJdao;
	/**
	 * 查询所有的配卡信息
	 * @return
	 */
	public List<CheckWithcard> CheckWithcardList(){
		return cwcMdao.queryCheckWithcard();
	}
	//模糊查询配卡信息
	public List<CheckWithcard> getSerchCheckWithcardList(int empId ){
		return cwcMdao.querySerchCheckWithcard(empId);
	}
	//存储新增配卡信息
	public void addCheckWithcard(CheckWithCardVO wcVO) {
		CheckWithcard wc=new CheckWithcard();
		wc.setWithcardId(wcVO.getWithcardId());
		wc.setEmp(emJdao.findByEmpId(wcVO.getEmpId()));
		wc.setCheckAccount(caJdao.findByaccountId(wcVO.getAccountId()));
		wc.setEffectivaDate(wcVO.getEffectivaDate());
		wc.setExpiryDate(wcVO.getExpiryDate());
		wc.setMaker(wcVO.getMaker());
		wc.setMakeTime(new Date());
		wc.setState("是");
		System.out.println(wc);
		cwcJdao.save(wc);
	}
	//修改配卡信息
	public void updateCheckWithcard(CheckUPWithCardVO wcVO) {
		CheckWithcard wc=new CheckWithcard();
		wc.setWithcardId(wcVO.getWithcardId());
		wc.setEmp(emJdao.findByEmpId(wcVO.getEmpId()));
		wc.setCheckAccount(caJdao.findByaccountId(wcVO.getAccountId()));
		wc.setEffectivaDate(wcVO.getEffectivaDate());
		wc.setExpiryDate(wcVO.getExpiryDate());
		wc.setMaker(wcVO.getMaker());
		wc.setMakeTime(wcVO.getMakeTime());
		wc.setUpdateEmp(wcVO.getUpdateEmp());
		wc.setUpdateTime(new Date());
		wc.setMakeTime(new Date());
		wc.setState("是");
		cwcJdao.save(wc);
	}
	public void deleteWithCard(int id) {
		cwcJdao.deleteById(id);
	}
}
